home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / MOVE.H < prev    next >
C/C++ Source or Header  |  1994-02-19  |  2KB  |  94 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #ifndef _MOVE_H
  4. #define _MOVE_H
  5.  
  6. class Move;
  7.  
  8. #include "board.h"
  9. #include <iostream.h>
  10.  
  11. class Move
  12. {
  13.     // basic "move" class, minimizes storage.
  14.     
  15.     public:
  16.     
  17.     Move( const Square start, 
  18.           const Square dest,
  19.           const Piece::PieceType promotion = Piece::Invalid)
  20.            : my_start(start),my_dest(dest),my_promotion(promotion)
  21.         {
  22.     }
  23.     
  24.     Move() :
  25.            my_start(Square::InvalidSquare), 
  26.        my_dest(Square::InvalidSquare), my_promotion(Piece::Invalid)
  27.     // constructs a null move
  28.     {
  29.         }
  30.     
  31.         virtual ~Move()
  32.     {
  33.     }
  34.     
  35.     static Move &NullMove();
  36.     
  37.     const int IsNull() const 
  38.     {
  39.        return (my_start == Square::InvalidSquare);
  40.     }
  41.     
  42.     const int operator == (const Move &m) const
  43.     {
  44.            return (my_start == m.my_start) && (my_dest == m.my_dest)
  45.            && (my_promotion == m.my_promotion);
  46.     }
  47.     
  48.     const int operator != (const Move &m) const
  49.     {
  50.         return !(*this == m);
  51.     }
  52.         
  53.     virtual void MakeNull() 
  54.     {
  55.        my_start = my_dest = Square::InvalidSquare;
  56.     }
  57.     
  58.     const Square &StartSquare() const 
  59.     {
  60.        return my_start;
  61.     }
  62.     
  63.     const Square &DestSquare() const 
  64.     {
  65.        return my_dest;
  66.         }
  67.     
  68.     const Piece::PieceType PromoteTo() const
  69.     {
  70.        return my_promotion;
  71.     }
  72.     
  73.     virtual const char *Image() const;
  74.     // returns a human-readable string.  CAUTION: reuses
  75.     // a static buffer for its return value
  76.     
  77.     static Move Value( char *str, const ColorType color );
  78.     // parses "str", assuming it contains a move for side "color",
  79.     // in the same string format returned by Image().  Returns
  80.     // NullMove if the string cannot be parsed.
  81.         
  82.     //friend istream & operator >> (istream &i, Move &move);
  83.     friend ostream & operator << (ostream &o, Move &move);
  84.         
  85.     protected:
  86.         
  87.         Square my_start;
  88.     Square my_dest;
  89.     Piece::PieceType my_promotion;
  90. };
  91.  
  92. #endif
  93.  
  94.